﻿Shader "Custom/TestShader13"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
        _Color("Color", color) = (1,1,1,1)
        _HorizontalAmount("HorizontalAmount", float) = 8
        _VerticalAmount("HorizontalAmount", float) = 8
        _Speed("Speed", float) = 8
	}
	SubShader
	{
		Tags { "RenderType"="Transparent" "Queue" = "Transparent" "Ignoreprojector" = "True" }

		Pass
		{
            Tags {"LightMode"= "ForwardBase"}
            
            ZWrite Off
            Blend SrcAlpha OneMinusSrcAlpha

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_fwdbase
			
			#include "UnityCG.cginc"

            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed4 _Color;
            float _HorizontalAmount;
            float _VerticalAmount;
            float _Speed;

			struct a2v
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};
			
			v2f vert (a2v v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
                float time = floor(_Time.y * _Speed);
                time = time %    (_HorizontalAmount * _VerticalAmount);

                float row = floor(time / _HorizontalAmount);
                float col = time - (_HorizontalAmount * row);

                float2 uv = float2(i.uv.x / _HorizontalAmount, i.uv.y / _VerticalAmount);
                uv.x += col / _HorizontalAmount;
                row = _VerticalAmount - row - 1;
                uv.y += row / _VerticalAmount;

				fixed4 color = tex2D(_MainTex, uv);
				return color;
			}
			ENDCG
		}
	}
}
